<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="../static/js/jquery/jquery-2.1.4.min.js" type="text/javascript"></script>
    <script src="../static/layui/layui.js" type="text/javascript"></script>
    <script src="../static/js/index/index.js" type="text/javascript"></script>
    <script src="../static/js/index/freezeheader.js" type="text/javascript"></script>
    <script src="../static/layui/lay/modules/layer.js" type="text/javascript"></script>
    <script src="../static/js/index/sliders.js" type="text/javascript"></script>
    <script src="../static/js/index/html5.js" type="text/javascript"></script>
    <link rel="stylesheet" href="../static/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../static/layui/css/modules/layer/default/layer.css"/>
    <link rel="stylesheet" href="../static/css/global.css"/>
    <link rel="stylesheet" href="./css/amazeui.min.css"/>
    <link rel="stylesheet" href="./css/admin.css"/>
    <link rel="stylesheet"
          href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <%--<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>--%>
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script
            src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <link rel="stylesheet" type="text/css"
          href="https://www.layuicdn.com/layui/css/layui.css"/>

    <script type="text/javascript" src="js/layer.js"></script>
    <link rel="stylesheet" href="css/layer.css">
</head>


<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">问题管理</strong>
            <small></small>
        </div>
    </div>

    <hr>
    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-4">
            <div class="layui-form-item">
                <div class="layui-input-inline" style="width:65%;">
                    <input type="text" id="keyName" name="keyContent" lay-verify="required" placeholder="请输入关键字"
                           class="layui-input">
                </div>
                <button class="layui-btn" onclick="getMessage();">搜索</button>
            </div>
        </div>
    </div>
    <div class="am-g">
        <div class="am-u-sm-12">
            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr>
                        <th class="table-type">问题ID</th>
                        <th class="table-type">问题内容</th>
                        <th class="table-type">问题提问者</th>
                        <th class="table-type">问题提问时间</th>
                        <th class="table-type">问题提问专业</th>
                        <th class="table-type">问题提问章节</th>
                        <th class="table-type">问题提问老师</th>
                        <th class="table-type">问题是否置顶</th>
                        <th class="table-type">问题是否已回答</th>
                        <th class="table-type">操作</th>
                    </tr>
                    </thead>
                    <tbody id="questionResult">
                    <c:forEach items="${questions}" var="question">
                        <tr>
                            <td>${question.questionId}</td>
                            <td class="am-hide-sm-only">${question.questionText}</td>
                            <td class="am-hide-sm-only">${question.questionQuizzerName}</td>
                            <td class="am-hide-sm-only"><fmt:formatDate value="${question.questionTime}"
                                                                        pattern="yyyy-MM-dd HH:mm:ss"/></td>
                            <td class="am-hide-sm-only">${question.questionSubject}</td>
                            <td class="am-hide-sm-only">${question.questionSection}</td>
                            <td class="am-hide-sm-only">${question.questionTeacherName}</td>
                            <c:set var="cnt01" scope="session"
                                   value="${question.questionStick}"></c:set>
                            <c:if test="${cnt01==0}">
                                <td class="am-hide-sm-only">未置顶</td>
                            </c:if>
                            <c:if test="${cnt01==1}">
                                <td class="am-hide-sm-only">已置顶</td>
                            </c:if>
                            <c:set var="cnt02" scope="session"
                                   value="${question.questionIsAnswer}"></c:set>
                            <c:if test="${cnt02==1}">
                                <td class="am-hide-sm-only">已回答</td>
                            </c:if>
                            <c:if test="${cnt02==0}">
                                <td class="am-hide-sm-only">未回答</td>
                            </c:if>

                            <td>
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                             onclick="delQuestion(${question.questionId})">删除</a>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <hr>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    var nowdatas;
    var inputName;
    function getMessage() {
        intputName = $("#keyName").val();
        $.ajax({
            type:"get",
            url:"/admin/question/search",
            data:{
                "keyContent":intputName
            },
            dataType:'json',
            success:function (data) {
                nowdatas = data;
                if (data.length==0) {
                    alert("没有搜索到对应的内容");
                }
                add();
            }
        })
    }

    function add() {
        $("#questionResult").empty();
        for (var i = 0;i<nowdatas.length;i++){
            str1 = '<tr><td>' + (i + 1) + '</td><td>' +
                nowdatas[i]['questionText']
                + '</td><td>' +
                nowdatas[i]['questionQuizzerName']
                + '</td><td>' +
                nowdatas[i]['questionTime']
                + '</td><td>'+
                nowdatas[i]['questionSubject']
                + '</td><td>' +
                nowdatas[i]['questionSection']
                + '</td><td>'+
                nowdatas[i]['questionTeacherName']
                + '</td>' +
                '<td>'+
                nowdatas[i]['questionStick']
                + '</td><td>'+
                nowdatas[i]['questionIsAnswer']
                + '</td><td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs"><dd></dd><a href="/answer/del/' + nowdatas['answerId'] + '">删除</a></div></div></td>' +
                +'</tr>';
            $("#questionResult").append(str1);
        }
    }

    function delQuestion(questionId) {
        inputName = questionId;
        $.ajax({
                type: "get",
                url: "/question/del",
                data: {"questionId": inputName},
                dataType: 'json',
                success: function (data) {
                    //  location.reload();
                    parent.location.reload();
                    alert("删除成功！");
                }
            }
        )
    }
</script>
</body>
</html>